﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using cmdb.keede.service;
using Newtonsoft.Json;
using cmdb.keede.common;
using cmdb.keede.entity;
using Microsoft.AspNetCore.Mvc.TagHelpers;
using Microsoft.Extensions.Logging;

namespace cmdb.keede.com.Controllers
{
    public class EnvironmentController : Controller
    {
        readonly IEnvironmentInfoService _environmentInfoService;

        public EnvironmentController(IEnvironmentInfoService environmentInfoService)
        {
            _environmentInfoService = environmentInfoService;
        }

        public IActionResult Index()
        {
            return View();
        }

        public async Task<BizResult<List<EnvironmentInfo>>> GetEnvironmentInfoes(int pageIndex, int pageSize)
        {
            return await _environmentInfoService.GetEnvironmentInfosAsync(pageIndex, pageSize);
        }

        public async Task<BizResult<EnvironmentInfo>> GetEnvironmentInfo(int id)
        {
            return await _environmentInfoService.GetEnvironmentInfoAsync(id);
        }

        public async Task<BizResult<bool>> DeleteEnvironmentInfo(int id)
        {
            return await _environmentInfoService.DeleteEnvironmentInfoAsync(id);
        }

        [HttpPost]
        public async Task<BizResult<bool>> AddOrUpdateEnvInfo(EnvironmentInfo env)
        {
            return await _environmentInfoService.AddOrUpdateEnvInfoAsync(env);
        }
    }
}